package com.example.laboratory.root_ui;

import android.app.Dialog;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import androidx.cardview.widget.CardView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import com.example.laboratory.R;
import com.example.laboratory.bean.Laboratory;
import com.example.laboratory.bean.TreeNode;
import com.example.laboratory.manager.UserInfoManager;
import com.example.laboratory.root_ui.AddLaboratory.AddLabContact;
import com.example.laboratory.root_ui.dialog.LabDialog;
import com.example.laboratory.root_ui.dialog.RecordDialog;
import com.example.laboratory.root_ui.dialog.UserDialog;
import com.example.laboratory.ui.base.BaseActivity;
import com.example.laboratory.ui.base.BasePresenterActivity;
import com.example.laboratory.ui.core.presenter.BasePresenter;
import com.example.laboratory.ui.user.Laboratory.LabContract;
import com.example.laboratory.ui.user.Laboratory.LabPresenter;
import com.example.laboratory.utils.IntentUtils;
import com.example.laboratory.utils.PreUtils;

import java.util.ArrayList;
import java.util.List;

public class RMainActivity extends BasePresenterActivity<LabPresenter> implements LabContract.ILabView{
    @BindView(R.id.root_lab)
    CardView rootLab;
    @BindView(R.id.root_record)
    CardView rootRecord;
    @BindView(R.id.root_lab_user)
    CardView rootLabUser;
    @BindView(R.id.root_notice)
    CardView rootNotice;
    @BindView(R.id.r_btn_login)
    Button rBtnLogin;
    private ArrayList<TreeNode> allNodes =new ArrayList<TreeNode>();
    /** 顶层元素结合*/
    private ArrayList<TreeNode> topNodes=new ArrayList<TreeNode>();
    @Override
    protected int getLayoutId() {
        return R.layout.r_activity_main;
    }

    List<Laboratory.RowsBean> mListBean=new ArrayList<>();
    @Override
    protected LabPresenter createPresenter() {
        return new LabPresenter();
    }

    @Override
    protected void initViews() {
        ButterKnife.bind(this);

    }


    @OnClick({R.id.root_lab, R.id.root_record, R.id.root_lab_user, R.id.root_notice, R.id.r_btn_login})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.root_lab:
                RLabListener();
                break;
            case R.id.root_record:
                RRecordListener();
                break;
            case R.id.root_lab_user:
                RUserListener();
                break;
            case R.id.root_notice:
                break;
            case R.id.r_btn_login:
                login();
                break;
        }
    }



    private void RLabListener() {
        List<String> list = new ArrayList<>();
        list.add("查询实验室信息");
        list.add("新增实验室");
        Dialog dialog = new LabDialog(this, list);
        dialog.show();
    }
    private void RRecordListener() {

        TreeNode topnode1= new TreeNode("查询巡检记录信息", TreeNode.TOP_LEVEL, "0", TreeNode.NO_PARENT+"", false, false);
        TreeNode topnode2= new TreeNode("实验室巡检", TreeNode.TOP_LEVEL , "1", TreeNode.NO_PARENT+"", true, false);
        topNodes.clear();
        //添加初始树元素
        topNodes.add(topnode1);
        topNodes.add(topnode2);

        allNodes.clear();
        for (int i = 0; i <mListBean.size() ; i++) {
            TreeNode childNode= new TreeNode(mListBean.get(i).getLabel(), TreeNode.TOP_LEVEL + 1, mListBean.get(i).getLabid(), topnode2.getId(), false, false);
            allNodes.add(childNode);
        }

        Dialog dialog = new RecordDialog(this,topNodes, allNodes);
        dialog.show();
    }
    private void RUserListener() {
        List<String> list = new ArrayList<>();
        list.add("实验室安全员信息");
        list.add("新增安全员");
        Dialog dialog = new UserDialog(this, list);
        dialog.show();
    }

    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        mPresenter.loadLabList(UserInfoManager.getUserInfo().getUid(),"");
    }

    private void login() {
        IntentUtils.goLogin(this);
        PreUtils.clearAll();
    }

    @Override
    public int getFirstPage() {
        return 0;
    }

    @Override
    public int getPage() {
        return 0;
    }

    @Override
    public void autoLoadMore() {

    }

    @Override
    public void clearListData() {

    }

    @Override
    public void showNoMore() {

    }

    @Override
    public void setData(List<Laboratory.RowsBean> data) {
        mListBean.clear();
        mListBean.addAll(data);
    }

    @Override
    public List<Laboratory.RowsBean> getData() {
        return null;
    }

    @Override
    public void showContent() {

    }
}
